#!/bin/bash
# Vytvor subor obsahujuci informacie o verzii fajru z gitu

BASE="`dirname $0`/.."
cd $BASE
VERSIONFILE="$BASE/version_info.php"

TIMESTAMP="`date +%s`"
DATE="`date '+%Y-%m-%d %H:%M:%S %Z'`"
VERSION="`git describe --tags --always --dirty --long`"
BRANCH="$(git symbolic-ref HEAD 2>/dev/null)" ||
BRANCH="(detached head)"
BRANCH=${BRANCH##refs/heads/}

function append() {
	echo "$1" >>$VERSIONFILE
}

function property() {
	append "  '$1'=>'$2',"
  echo "$1: $2"
}

echo "<?php" >$VERSIONFILE
append "// This file was automatically generated by scripts/make_version.sh"
append "// Do not modify it. Run scripts/make_version.sh instead"
append "return array("

property branch "$BRANCH"
property timestamp "$TIMESTAMP"
property date "$DATE"
property revision "git-$VERSION"

append ");"
